#ifndef DIALOGPROCESSVIDEO_H
#define DIALOGPROCESSVIDEO_H

#include <QMutex>
#include <QMetaType>
#include <QDialog>
#include <QDir>
#include <QThread>
#include <QTimer>
#include <QMessageBox>
#include <opencv2/opencv.hpp>

#include "lineprocessing.h"
#include "dialog_bigpicture.h"
#include "triangulate3d.h"
#include "feexport.h"

using namespace cv;

namespace Ui {
class DialogProcessVideo;
}

class DialogProcessVideo : public QDialog
{
    Q_OBJECT
    
public:
    explicit DialogProcessVideo(QWidget *parent = 0);
    ~DialogProcessVideo();

    QString projName;
    QString eventName;
    QString camRes;

    void init();  //not sure if I need this
    
signals:
    void doItLinProc(); // signal to start the line processors
    void termLinProc(); // to signal the Line Processors to stop work
    void updateBigPic(int, QImage);

    void doItTriang3D(); //signal to start the 3D transformation
    void termTriang3D(); //signal to terminate 3D transformation

    void doItFEexport();


private slots:
    void on_pushButton_LineProcessing_clicked();

    void on_pushButton_Playback_clicked();

    void TimerEvent();

    void on_checkBox_clicked();

    void updateProgressBar0(int progress);  //line processing status update for cam0 video
    void updateProgressBar1(int progress);  //line processing status update for cam1 video

    void updateLineImage0(); //cam0 line results
    void updateLineImage1(); //cam1 line results

    void on_pushButton_TestParams_clicked();

    void setLineProcessingParams(lineProcessing *lineProc);

    void on_pushButton_Cam0_bigPicture_clicked();

    void on_pushButton_Cam1_bigPicture_clicked();

    void on_pushButton_triang3D_clicked();

    void lineProcessingDone();

    void triang3DProcessingDone();

    void on_pushButton_FE_export_clicked();
    void FE_export_done();

private:
    Ui::DialogProcessVideo *ui;
    lineProcessing *lineProc0, *lineProc1;
    QThread *thread0, *thread1;
    bool runningLineProcessing;

    QString videoname0, videoname1; //file names of the event video
    VideoCapture vid0, vid1;    //video file capture objects
    QTimer* timer;   //for video playback
    int framesVid;  //total frames in the captured video
    float timeVid;  //total time of the captured video
    bool infoGood;
    Mat matVid;
    bool looping;  //if video playback is looping
    bool playing;  //if playing back

    QDir dirResults;

    QString output0, output1; // output file names for the line processing results
    QString output3D_0, output3D_1; //output file names for the 3D triangulation results

    bool lineProcessingFilter;  // yes/no: use Gauss filter on line processing
    uchar lineProcessingMinConfForExport; //minimum Confidence for exporting
    int lineProcessingLineAngleRatio;  //line angle ratio for three pass search
    uchar lineProcessingPeakMinThreashold;  //minimum value for consideration as a peak
    uchar lineProcessingMinCutoff;  //Lower threshold to ignore the low level noise
    int lineProcessingTestParamLoc; //location in the video where we will show a test of the parameters

    bigPicture *bigPic;
    QImage img0, img1;

    triangulate3D *triang3D_0, *triang3D_1;
    bool runningTriang3D;

    FEexport *fe;


};

#endif // DIALOGPROCESSVIDEO_H
